home *** CD-ROM | disk | FTP | other *** search
- unit Test_Window;
-
- {File name: Test_Window.Pas}
- {Function: Handle a Window}
- {History: 3/14/89 Original by Prototyper. }
-
- interface
- uses
- MyGlobals, MyScroll;
-
- procedure Close_Test_Window (whichWindow: WindowPtr); {Close our window}
- procedure Open_Test_Window; {Open our window and draw everything}
- procedure Update_Test_Window; {Update our window, someone uncovered a part of us}
- procedure Do_Test_Window (myEvent: EventRecord); {Handle action to our window, like controls}
-
- implementation
- {=================================}
- procedure Close_Test_Window; {Close our window}
- begin
- if (MyWindow <> nil) and (MyWindow = whichWindow) then {Close if this is us}
- begin
- DisposeWindow(MyWindow); {Clear window and controls}
- MyWindow := nil;
- TEDispose(EditText); {dispose of TE record}
- EditText := nil;
- end; {End for if (MyWindow<>nil)}
- end; {of Close_Test_Window}
-
- procedure UpDate_Test_Window; {Update our window, someone uncovered a part of us}
- begin
- PenNormal;
- EraseRect(paneRect); {redraw dividing lines between two panes if any}
- SetRect(paneRect, 0, Split^^.contrlValue + 1, Split^^.contrlRect.left, Split^^.contrlValue + 5);
- if ((Split^^.contrlValue > 0) and (Split^^.contrlValue < Split^^.contrlMax)) then {is there enough room?}
- begin
- FrameRect(paneRect);
- end;
-
- if (EditText <> nil) then {update EditText to both panes}
- begin
- TEDeactivate(EditText);
- SetEditText(1);
- TEUpdate(MyWindow^.portRect, EditText); {Update Lower pane}
- SetEditText(2);
- TEUpdate(MyWindow^.portRect, EditText); {Update Upper pane}
- SetEditText(activePane);
- TEActivate(EditText);
- end;
-
- DrawControls(MyWindow); {Draw all the controls}
- DrawGrowIcon(MyWindow); {Draw the Grow box}
- end; {of Update_Test_Window}
-
- procedure Open_Test_Window; {Open our window and draw everything}
- var
- sTemp: str255; { For initializing the text window}
- begin {Start of Window open routine}
- if (MyWindow = nil) then {Handle an open when already opened}
- begin
- MyWindow := GetNewWindow(WindowID, nil, Pointer(-1)); {Get the window from the resource file}
- SelectWindow(MyWindow); {Bring our window to the front}
- SetPort(MyWindow); {Prepare to write into our window}
-
- { Make a scroll bars}
- Scroll[2] := GetNewControl(Scrollbar2, MyWindow); {Make a new scrollbar}
- Scroll[1] := GetNewControl(Scrollbar1, MyWindow); {Make a new scrollbar}
- { Make a splitbar}
- Split := GetNewControl(Splitbar, MyWindow); {Make a new scrollbar}
-
- {Set max/min and initial values of scrollbars}
- SetCtlMax(Scroll[1], 0);
- SetCtlMin(Scroll[1], 0);
- SetCtlValue(Scroll[1], 0);
- SetCtlMax(Scroll[2], 0);
- SetCtlMin(Scroll[2], 0);
- SetCtlValue(Scroll[2], 0);
- FixScrollbarRects; {redraw scroll/split bars done}
-
- FixTextRects; {get TE record's rectangles for switching}
-
- activePane := 1; {Set active pane}
-
- EditText := TENew(viewRect[1], destRect[1]);
- HLock(Handle(EditText)); { set up attributes of of TE record}
- with EditText^^ do
- begin
- txFont := applFont;
- fontAscent := 12;
- lineHeight := 12 + 3 + 1;
- end;
- HUnLock(Handle(EditText));
- sTemp := 'Splitbar available for those with split personalities';
- TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), EditText);
- FixTextRects; {get TE record's rectangles for switching}
- TEActivate(EditText);
- ShowWindow(MyWindow);
- UpDate_Test_Window; {Do an update to draw rest of items}
- end {End for if (MyWindow<>nil)}
- else
- SelectWindow(MyWindow); {Already open, so show it}
- end; {of Open_Test_Window}
-
- procedure HandleScrollBars (theControl: ControlHandle; thePart: integer); {scroll Text while in scrollbar}
- var
- oldValue, delta, pane: integer; {Value of the scrollbar}
- begin
- case GetCRefCon(theControl) of {find which pane}
- ScrollBar1:
- pane := 1;
- ScrollBar2:
- pane := 2;
- end;
-
- case thePart of {get delta}
- inUpButton:
- delta := -1;
- inDownButton:
- delta := 1;
- inPageUp:
- delta := -(viewRect[pane].bottom - viewRect[pane].top) div EditText^^.lineHeight;
- inPageDown:
- delta := (viewRect[pane].bottom - viewRect[pane].top) div EditText^^.lineHeight;
- end;
-
- if thePart <> 0 then {set Control's value and adjust text}
- begin
- oldValue := GetCtlValue(theControl);
- SetCtlValue(theControl, oldValue + delta);
- AdjustText(pane);
- end;
- end; {of HandleScrollBars}
-
- procedure Do_Test_Window; {Handle action to our window, like controls}
- var
- RefCon: integer; {RefCon for controls}
- code: integer; {Location of event in window or controls}
- theValue: integer; {Current value of a control}
- whichWindow: WindowPtr; {Window pointer where event happened}
- myPt: Point; {Point where event happened}
- theControl: ControlHandle; {Handle for a control}
- extend: boolean; {TE extending with Shift key modifier}
-
- procedure Do_A_ScrollBar (code: integer); {Handle a ScrollBar being pressed}
- begin {Handle a ScrollBar being pressed}
- RefCon := GetCRefCon(theControl); {get control refcon}
-
- case RefCon of {Select correct scrollbar}
- Splitbar: {Splitbar}
- begin {start for this scroll bar}
- TEDeactivate(EditText);
- code := TrackControl(theControl, myPt, nil); {Let the OS drag it around}
- FixScrollbarRects;
- TEActivate(EditText);
- end; {end for this scroll bar}
-
- Scrollbar1:{Scrollbars}
- begin
- {start for this scroll bar}
- if code <> inThumb then
- code := TrackControl(theControl, myPt, @HandleScrollBars)
- else
- begin
- code := TrackControl(theControl, myPt, nil);
- AdjustText(1);
- end;
- end; {end for this scroll bar}
-
- Scrollbar2: {Scrollbars}
- begin {start for this scroll bar}
- if code <> inThumb then
- code := TrackControl(theControl, myPt, @HandleScrollBars)
- else
- begin
- code := TrackControl(theControl, myPt, nil);
- AdjustText(2);
- end;
- end; {end for this scroll bar}
- end; {end of case}
- end; {Handle a ScrollBar being pressed}
-
- begin {Start of Window handler}
- if (MyWindow <> nil) then {Handle only when the window is valid}
- begin
- code := FindWindow(myEvent.where, whichWindow); {Get where in window and which window}
-
- if (myEvent.what = MouseDown) and (MyWindow = whichWindow) then { convert coords }
- begin {}
- myPt := myEvent.where; {Get mouse position}
- GlobalToLocal(myPt);
- end;
-
- if (MyWindow = whichWindow) and (code = inContent) then {for our window}
- begin
- TEDeactivate(EditText); {remove hilighting}
- if PtInRect(MyPt, viewRect[1]) then {determine which pane mouse down in}
- begin
- SetEditText(1);
- activePane := 1;
- end
- else if PtInRect(MyPt, viewRect[2]) then
- begin
- SetEditText(2);
- activePane := 2;
- end;
- TEActivate(EditText); {put highlighting back}
-
- if PtInRect(MyPt, EditText^^.viewRect) then {do click routine for TE record}
- begin
- extend := (BitAnd(myEvent.modifiers, ShiftKey) <> 0);
- TEClick(myPt, extend, EditText);
- end;
-
- code := FindControl(myPt, whichWindow, theControl); {Get type of control}
- if (code <> 0) then {Check type of control}
- code := TrackControl(theControl, myPt, nil); {Track the control}
-
- if (code = inUpButton) or (code = inDownButton) or (code = inThumb) or (code = inPageDown) or (code = inPageUp) then
- Do_A_ScrollBar(code); {Do scrollbars}
-
- end; {End for if (MyWindow=whichWindow)}
- end; {End for if (MyWindow<>nil)}
- end; {End of procedure}
-
- end. {End of unit}